package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.ActionFactory;
import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.commands.PicInstruction;
import de.dhbw.karlsruhe.picsim.model.cpu.PicInstructionFacade;
import de.dhbw.karlsruhe.picsim.util.Bits;
import de.dhbw.karlsruhe.picsim.util.impl.BitUtilities;
import de.dhbw.karlsruhe.picsim.util.impl.Lengths;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: May 3, 2010
 * Time: 3:27:49 PM
 */
public class GoTo implements PicInstruction {
    private static final Log log = LogFactory.getLog(GoTo.class);
    private final Bits argument;

    public GoTo(final Bits argument) {
        this.argument = BitUtilities.clone(argument);
        if (argument.getLength() != Lengths.CALL_GOTO_ARGUMENT_LENGTH) {
            throw new IllegalArgumentException(argument.toString());
        }
    }

    @NotNull
    @Override
    public List<? extends PicAction> getActions(@NotNull final PicInstructionFacade pic) {
        log.debug("Goto the argument place");

        final List<PicAction> list = new ArrayList<PicAction>();
        final ActionFactory actionFactory = pic.getActionFactory();

        list.add(actionFactory.createElevenBitJump(argument));
        return list;
    }
}
